package com.teamit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teamit.entity.Document;
import com.teamit.service.DocumentService;
import com.teamit.util.web.ServletUtil;

public class DocEditServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = (String) request.getParameter("id");
		//System.out.println(id);
		DocumentService ds = new DocumentService();
		Document document = ds.findDocumentById(id);
		request.setAttribute("document", document);
		//System.out.println(document.getTitle());
		ServletUtil.forword(request, response, "docedit");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		DocumentService ds = new DocumentService();
		
		request.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		String id = request.getParameter("id");
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		System.out.println(id);
		System.out.println(title);
		System.out.println(content);
		ds.edit(id,title,content);
		response.sendRedirect("document.jspx");
	}

}
